Intra-function code generation
Description
Example programs
Description
Modify the parser to generate assembly like code for each function defined
in the input program. The specific requirements are:
-
As in previous projects, your parser should ignore (but copy) "meta-statements"
at the beginningof the program.
-
The output program uses the same grammar as the input program with the
following modifications. This is a precise grammar defintion.
But you should not worry about parsing this grammar since you are not going
to compile the output program.
-
<assignment> --> ID equal_sign <operand> <operation>
<operand> semicolon | ID equal_sign <operand> semicolon
-
<operand> --> NUMBER | ID
-
change all mentioning of <expression> with <operand>
-
Of course, now IDs are array references to the local memory array
-
CS 454 students should generate code for <if-statement> and <while-statement>.
The output grammar uses the following:
-
<if-statement> --> if left_parenthesis <operand> <comparison
op> <operand> right_parenthesis goto ID semicolon
-
<goto-statement> --> goto ID semicolon
-
<label-statement> --> ID colon <non-empty statement>
-
The output program should be compilable by CC compiler and have the same
behavior as the input program.
Test programs
Three example programs and their sample generated
programs are here. Scroll down to see the content of README.